package com.dk.controller;

import com.dk.pojo.Menu;
import com.dk.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("menu")
public class MenuController {
    @Autowired
    private MenuService menuService;
    @RequestMapping("getInfo")
    @ResponseBody
    public List<Map<String, Object>>  getInfo(){
        List<Map<String, Object>> list = menuService.getInfo();
        return  list;
    }
    @RequestMapping("toZtree")
    public String toZtree(){
        return "zTree";
    }
    @RequestMapping("getInfoZtree")
    @ResponseBody
    public List<Map<String, Object>>  getInfozTree(){
        List<Map<String, Object>> list = menuService.getInfozTree();
        return  list;
    }
    @RequestMapping("toAdd")
    public String toAdd(){
        return "menu/menuAdd";
    }
    @RequestMapping("add")
    @ResponseBody
    public Boolean add(Menu menu){
        return menuService.insertMenuInfo(menu);
    }
    @RequestMapping("deleteById")
    @ResponseBody
    public Boolean deleteById(Integer id){
        return menuService.deleteById(id);
    }
    @RequestMapping("toUpdate/{id}")
    public String toUpdate(@PathVariable("id")Integer id, Model model){
        Menu menu =  menuService.selectById(id);
        model.addAttribute("menu",menu);
        return "menu/menuUpdate";
    }
    @RequestMapping("update")
    @ResponseBody
    public Boolean update(Menu menu){
        return menuService.update(menu);
    }
    @RequestMapping("getInfoZtreeChecked/{rid}")
    @ResponseBody
    public List<Map<String,Object>>  getInfoZtreeChecked(@PathVariable("rid")Integer rid){
        List<Map<String,Object>> list = menuService.getInfoZtreeChecked(rid);
        return list;
    }
}
